<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td>
					<a class="mini-button" iconCls="icon-add" onclick="onAddLeave('填写休假单')">填写休假单</a>
					<a class="mini-button" iconCls="icon-edit" onclick="onEditLeave()">编辑休假单</a>
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
    <div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20"
		url="leave_info_view.do" 
		style="width:100%;height:100%;" allowCellSelect="true" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn" headerAlign="center">#</div>
			<div field="leaveTypeName" width="100" headerAlign="center" align="center">休假类型</div>
			<div field="startTime" width="100" allowSort="true" headerAlign="center" align="center">休假开始时间</div>
			<div field="endTime" width="100" allowSort="true" headerAlign="center" align="center">休假结束时间</div>
			<div field="days" width="100" headerAlign="center" align="center">休假天数</div>
			<div width="120" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.reload();
	
	function onAddLeave(title) {
	    mini.open({
	   		url: "leave_info_add.do",
	   		allowResize:false,
           	title: title, width: 930, height: 430,
           	onload: function () {
               var iframe = this.getIFrameEl();
               var data = { action:"new" };
               iframe.contentWindow.SetData(data);
       		},
    	   	ondestroy: function (action) {
    	   		if(action == 'succ'){
    	   			mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
    	   			grid.reload();
    	   		}
            }
     	});
	}
	
	//修改
	function onEditLeave() {
	    var row = grid.getSelected();
	    if (row) {
	    	if(row.status == '0'){
	    		mini.alert("未回收无法编辑!");
	    	}else{
		        mini.open({
		            url: "medical_backleave_edit.do",
		            allowResize:false,
		            title: "编辑用户信息", width: 930, height: 430,
		            onload: function () {
		                var iframe = this.getIFrameEl();
		                var data = { action: "edit",row:row };
		                iframe.contentWindow.SetData(data);
		            },
		            ondestroy: function (action) {
		            	if(action == 'succ'){
		            		mini.showMessageBox({
		                        title: "提示",
		                        showModal:false,
		                        iconCls: "mini-messagebox-info",
		                        message: "修改成功！",
		                        timeout: 3000,
		                        x: 'right',
		                        y: 'bottom'
		                    });
		                	grid.reload();
		            	}
		            }
		        });
	    	}
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
	
	function onActionRenderer(e) {
	    var s = "<a href='javascript:seeDetails();'>查看详细</a>";
	    if(e.row.status == '0'){
	    	s +="&nbsp;<a href='javascript:back();'>回收</a>";
	    }else if(e.row.status == '1'){
	    	s +="&nbsp;<a href='javascript:remove();'>删除</a>";
	    }
	    return s;
	}
	
	//查看详情
	function seeDetails() {
	    var row = grid.getSelected();
	    if (row) {
	        mini.open({
	            url: "init_leave_details.do",
	            allowResize:false,
	            title: "休假单信息", width: 500, height: 430,
	            onload: function () {
	                var iframe = this.getIFrameEl();
	                var data = { row: row };
	                iframe.contentWindow.SetData(data);
	            }
	        });
	    }
	}
	
	//回收休假单
	function back() {
	    var row = grid.getSelected();
	    if (row) {
	        $.post("leave_status_back.do",{id:row.id},function(data){
	        	if(data.success){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "回收成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom',
	                });
					grid.load();
	        	}else{
	        		mini.alert("已审批，回收失败！");
	        		grid.load();
	        	}
	        }, "json");
	    }
	}
	
	//删除
	function remove() {
	    var row = grid.getSelected();
	    if (row) {
	    	mini.confirm("确定删除选中记录？", "删除",
               function (action) {
	    			if(action == 'ok'){
						$.post('leave_info_del.do', {id: row.id}, function(data){
	    					if(data.success){
		    					mini.showMessageBox({
				                    title: "提示",
				                    showModal:false,
				                    iconCls: "mini-messagebox-info",
				                    message: "删除成功！",
				                    timeout: 3000,
				                    x: 'right',
				                    y: 'bottom',
				                });
	    						grid.load();
	    					}else{
	    						mini.alert("id不能为空，删除失败！");
	    					}
	   					}, "json");
	    			}
            	}
	    	);
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
</script>
</body>
</html>